home *** CD-ROM | disk | FTP | other *** search
- #ifndef FWPRITAS_H
- #define FWPRITAS_H
- //========================================================================================
- //
- // File: FWPriTas.h
- // Release Version: $ 1.0d1 $
- //
- // Creation Date: 3/25/94
- //
- // Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include <stddef.h>
-
- #if defined(FW_BUILD_MAC) && !defined(FW_HAS_INSTANCE_DATA)
- #define FW_HAS_INSTANCE_DATA
- #endif
-
- //========================================================================================
- // STRUCT FW_SPrivTaskGlobalsHeader
- //
- // By convention, the task globals area has this header structure.
- //========================================================================================
-
- struct FW_SPrivTaskGlobalsHeader
- {
- short gPrivTaskGlobalsSize;
- void* gThisBlock;
- };
-
- //========================================================================================
- // CLASS FW_CPrivTaskGlobals
- // An interface for per task globals. A set of DLLs and an application can share task
- // specific global data using this interface.
- //========================================================================================
-
- class FW_CPrivTaskGlobals
- {
-
- public:
-
- static void* GetTaskGlobals();
- // Get a pointer into the globals block
-
- static void* GetTaskGlobals(unsigned short offset);
- // Get a pointer into the globals block, positioned at offset from start of block
-
- static void Initialize();
- // Initialize task data for this component.
-
- static void Terminate();
- // Terminate (cleanup) task data for this component.
-
- static FW_SPrivTaskGlobalsHeader& GetTaskGlobalsHeader();
- // Terminate (cleanup) task data for this component.
-
- static void UsesTaskGlobalData(unsigned short offset, unsigned short size);
- // Inform task globals mechanism that component uses specified data slots
- // This function should be called before calling GetTaskGlobals(offset),
- // but only if offset+size > kDefaultGlobalsBlockSize.
-
- private:
-
- static void* PrivGetTaskGlobals();
- // Get the pointer to the task globals block.
- // Pointer may be NULL, indicating globals aren't initialized.
-
- static void PrivSetTaskGlobals(void* globals);
- // Set the pointer to the task globals block.
- // Client is responsible for disposing the previous block, if any.
-
- static void* AllocateTaskGlobals();
- // Get the pointer to the task globals block.
- // Pointer may be NULL, indicating globals aren't initialized.
-
- static void ResizeTaskGlobals(unsigned short size);
- // Resize the task globals block.
-
- static void FatalExit();
- // Exit application due to failure to allocate task globals block.
-
- enum
- {
- kTaskGlobalsHeaderOffset = 0,
- kDefaultGlobalsBlockSize = 256
- };
-
- FW_CPrivTaskGlobals();
- // This class should never be instantiated -- all members are static
-
- #ifdef FW_HAS_INSTANCE_DATA
- static void* gTaskGlobalData;
- #endif
- };
-
- #ifdef FW_BUILD_WIN
- //----------------------------------------------------------------------------------------
- // Extern routines written in assembler
- //----------------------------------------------------------------------------------------
- #ifdef FW_BUILD_WIN16
- extern "C"
- {
- #endif
- void* FW_PrivWinGetTaskGlobals();
- void FW_PrivWinSetTaskGlobals(void* p);
- #ifdef FW_BUILD_WIN16
- };
- #endif
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivTaskGlobals::PrivGetTaskGlobals
- //----------------------------------------------------------------------------------------
-
- inline void* FW_CPrivTaskGlobals::PrivGetTaskGlobals()
- {
- #if defined(FW_HAS_INSTANCE_DATA)
- return gTaskGlobalData;
- #elif defined(FW_BUILD_WIN)
- return FW_PrivWinGetTaskGlobals();
- #else
- Error; // Unknown configuration for task global data
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivTaskGlobals::PrivSetTaskGlobals
- //----------------------------------------------------------------------------------------
-
- inline void FW_CPrivTaskGlobals::PrivSetTaskGlobals(void* globals)
- {
- #if defined(FW_HAS_INSTANCE_DATA)
- gTaskGlobalData = globals;
- #elif defined(FW_BUILD_WIN)
- FW_PrivWinSetTaskGlobals(globals);
- #else
- Error; // Unknown configuration for task global data
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivTaskGlobals::GetTaskGlobals
- //----------------------------------------------------------------------------------------
-
- inline void* FW_CPrivTaskGlobals::GetTaskGlobals(unsigned short offset)
- {
- return (void*) ((char*)GetTaskGlobals()+offset);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivTaskGlobals::GetTaskGlobalsHeader
- //----------------------------------------------------------------------------------------
-
- inline FW_SPrivTaskGlobalsHeader& FW_CPrivTaskGlobals::GetTaskGlobalsHeader()
- {
- return *((FW_SPrivTaskGlobalsHeader*)GetTaskGlobals(kTaskGlobalsHeaderOffset));
- }
-
- #endif
-
-